<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css"/>
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <script src="/js/plugins/ckeditor/ckeditor.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css"/>
    <script src="js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/plugins/dialog/dialog.min.js"></script>


</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title">广州攻略</h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <i class="fa fa-heart"><span> 0</span> 收藏</i>
        <i class="fa fa-thumbs-up"><span> 0</span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot">
            <h6>大家都在看</h6>
            <div render-loop="list">
                <a href="travelContent.html" render-fun="handler" render-key="list.id">
                    <button class="btn" render-html="list.title">上下九</button>
                </a>
            </div>
        </div>
        <div class="catalogs">
            <div render-loop="list">
                <div class="container detail">
                    <h6 render-html="list.name">01/概况</h6>
                    <div render-loop="list.details">
                        <a render-fun="handler" render-key="list.details.id" href="strategyDetails.html">
                            <button class="btn" render-html="list.details.title">广州速览</button>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <div class="tab-pane fade " id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div>
                <span>价格便宜</span>
                <span>很热闹</span>
                <span>交通方便</span>
                <span>吃的很多</span>
                <span>风景优美</span>
                <span>美食很多</span>
                <span>很特别</span>
                <span>爱上这座城</span>
                <span>住宿方便</span>
                <span>刚刚</span>
            </div>
        </div>
        <hr>

        <div id="comment">

            <div render-loop="list">
                <div class="container row comment ">
                    <div class="col-2 comment-head">
                        <a href="userProfiles.html">

                            <img class="rounded-circle" render-src="list.user.headImgUrl">

                        </a>
                    </div>


                    <div class="col comment-right">

                        <p class="authorName"><span render-html="list.user.nickName"></span></p>
                        <span class="comment-star" render-fun="star" render-key="list.id">
                            <!--动态回显星星的地方-->
                        </span>


                        <span class="comment-date" render-html="list.createTime"></span>

                        <div class="comment-content">
                            <a render-fun="hand" render-key="list.id" render-html="list.comment">jqueryRatingStars
                                <p></p>
                            </a>
                        </div>


                        <ul class="comment-img">
                            <li>
                                <span>
                                <img render-src="list.coverUrl">
                                 </span>
                            </li>
                        </ul>
                        <input name="id" type="hidden" id="id">

                        <div class="d-flex icon">


                            <a render-fun="hand" render-key="list.id">
                                <i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>
                            </a>

                            <!--<a render-fun="handup" render-key="list.id" >
                                <i class="fa  fa-commenting-o " style="margin-right: 10px"> 编辑 </i>
                            </a>-->
                            <!--<a class="btnlike"  render-fun="addlike" render-key="list.id">-->
                            <!--<input type="hidden"  class="classlike" render-value="list.id">-->
                            <!--<i class="fa fa-thumbs-o-up btn-like" name="like"   > <span>0</span> </i>-->
                            <!--</a> -->
                            <a class="btnlike" render-fun="addlike" render-key="list.id">
                                <input type="hidden" class="classlike" render-value="list.id">
                                <i class="classlike fa fa-thumbs-o-up"
                                   name="like" render-fun="addtarget" render-key="list.id">
                                    <span render-html="list.likeCount">0</span> </i>
                            </a>

                        </div>

                    </div>

                </div>

            </div>
        </div>


    </div>

</div>
</div>

<div class="operation">
    <button class="btn">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>


<script>
    var userId = getUser().id;
    var strategyId = getParams().strategyId;
    var id = getParams().strategyId;
    $(function () {

        var userId = getUser().id;
        var currentPage = 1;
        var pages;
        var comment;
        $.get("/strategys/" + id + "/catalogs", function (data) {
            console.log(data);
            $(".title").html(data[0].strategyTitle);
            $(".catalogs").renderValues({list: data}, {
                handler: function (ele, val) {
                    ele.href = "strategyDetails.html?id=" + val;
                }
            })
        })

        //大家都在看,查询当前攻略所属地区阅读量前三的游记进行渲染
        $.get("/travels/hot/" + id, function (data) {

            $(".hot").renderValues(data, {
                handler: function (ele, val) {
                    ele.href = "travelContent.html?id=" + val;
                }
            })

        })


        $("#commentBtn").click(function () {
            window.location.href = "addComment.html?strategyId=" + id;
        })

        //回显点评
        $.get("/strategys/comment/" + id, function (data) {
            pages = data.pages;
            comment = data.list;
            $("#comment").renderValues(data, {
                star: function (ev, val) {
                    $(ev).attr("id", "star" + val);
                    //console.log(ev);
                },
                hand: function (ele, value) {
                    ele.href = "/strategyComment.html?id=" + value;

                },
                handup: function (ele, value) {
                    ele.href = "addComment.html?strategyId=" + value;
                    $(".likeid").val(value);
                },
                addtarget: function (ele, value) {

                    ele.setAttribute("value", value);


                }

            });

            $(".classlike").each(function (index, ele) {
                var stratId = ele.getAttribute("value");

                $.get("/strategys/strategyLike/" + strategyId, {userId: userId, strategyId: stratId}, function (data) {
                    console.log(data)
                    if (data) {
                        $(ele).attr("class", "classlike fa fa-thumbs-up");
                    }
                })


            });

            $("[name='like']").on("click", function () {
                var id = ($(this).prev().val());
                console.log($(this).attr("class"))
                var span = $(this);
                var num = this.firstElementChild.innerHTML;
                num = parseInt(num);
                console.log(span);
                var likestpye = $(this).attr("class")
                if (likestpye == "classlike fa fa-thumbs-o-up") {
                    $(this).attr("class", "classlike fa fa-thumbs-up");
                    this.firstElementChild.innerHTML = num + 1;
                    console.log(this);
                    $.ajax({
                        url: "/strategys/strategyLike",
                        type: "post",
                        data: {strategyId: id, userId: userId},
                        success: function (data) {
                            if (data.success) {
                            } else {
                                alert("点赞失败!");
                            }
                        }
                    });
                    $(this)
                }
                if (likestpye == "classlike fa fa-thumbs-up") {
                    $(this).attr("class", "classlike fa fa-thumbs-o-up");
                    this.firstElementChild.innerHTML = num - 1;
                    $.ajax({
                        url: "/strategys/strategyLike/{id}",
                        type: "post",
                        data: {_method: "DELETE", strategyId: id, userId: userId},
                        success: function (data) {
                            if (data.success) {

                            } else {
                                alert("点赞失败!");
                            }
                        }
                    });
                }

            })

            $.each(data.list, function (index, ele) {
                creatStart(ele.state * 2, ele.id)

            })


        })


        //回显点评五角星的函数
        function creatStart(count, id) {
            var star = $("  <i class=\"fa fa-star-o\"></i>\n" +
                "                            <i class=\"fa fa-star-o\"></i>\n" +
                "                            <i class=\"fa fa-star-o\"></i>\n" +
                "                            <i class=\"fa fa-star-o\"></i>\n" +
                "                            <i class=\"fa fa-star-o\"></i>");
            for (var i = 0; i < count; i++) {
                var s = star[i];
                $(s).removeClass("fa-star-o")
                $(s).addClass("fa fa-star");
            }
            $(star).appendTo("#star" + id + "");
        }

        $(window).scroll(function () {
            if (isFull()) {
                if (currentPage < pages) {
                    $.get("/strategys/comment/" + id, {currentPage: ++currentPage}, function (data) {
                        $.merge(comment, data.list);


                        $("#comment").renderValues({list: comment}, {
                            star: function (ev, val) {
                                $(ev).attr("id", "star" + val);

                            },
                            hand: function (ele, value) {
                                ele.href = "/strategyComment.html?id=" + value;
                            },
                            addtarget: function (ele, value) {
                                ele.setAttribute("value", value);

                            }


                        });

                        $(".classlike").each(function (index, ele) {
                            var stratId = ele.getAttribute("value");

                            $.get("/strategys/strategyLike/" + strategyId, {
                                userId: userId,
                                strategyId: stratId
                            }, function (data) {
                                console.log(data)
                                if (data) {
                                    $(ele).attr("class", "classlike fa fa-thumbs-up");
                                }
                            })


                        });
                        $("[name='like']").on("click", function () {
                            var id = ($(this).prev().val());
                            console.log(id)
                            console.log($(this).attr("class"))
                            var num = this.firstElementChild.innerHTML;
                            num = parseInt(num);
                            var likestpye = $(this).attr("class")
                            if (likestpye == "classlike fa fa-thumbs-o-up") {
                                this.firstElementChild.innerHTML = num + 1;
                                $(this).attr("class", "classlike fa fa-thumbs-up");
                                $.ajax({

                                    url: "/strategys/strategyLike",
                                    type: "post",
                                    data: {strategyId: id, userId: userId},
                                    success: function (data) {
                                        if (data.success) {
                                            /!*alert("上传成功!");*!/
                                            console.log(5555);
                                        } else {
                                            alert("点赞失败!");
                                        }
                                    }
                                });
                            }
                            if (likestpye == "classlike fa fa-thumbs-up") {
                                $(this).attr("class", "classlike fa fa-thumbs-o-up")
                                this.firstElementChild.innerHTML = num - 1;
                                $.ajax({
                                    url: "/strategys/strategyLike/{id}",
                                    type: "post",
                                    data: {_method: "DELETE", strategyId: id, userId: userId},
                                    success: function (data) {
                                        if (data.success) {
                                            /!*alert("上传成功!");*!/
                                            console.log(5555);
                                        } else {
                                            alert("点赞失败!");
                                        }
                                    }
                                });
                            }


                            if (likestpye == "fa fa-thumbs-up") {
                                $(this).attr("class", "fa fa-thumbs-o-up")
                                $.ajax({
                                    url: "/strategys/strategyLike/{id}",
                                    type: "post",
                                    data: {_method: "DELETE", strategyId: id, userId: userId},
                                    success: function (data) {
                                        if (data.success) {
                                            /!*alert("上传成功!");*!/
                                            console.log(5555);
                                        } else {
                                            alert("点赞失败!");
                                        }
                                    }
                                });
                            }


                        })
                        $.each({list: comment}.list, function (index, ele) {
                            creatStart(ele.state * 2, ele.id)

                        })

                    })
                } else {
                    $(document).dialog({
                        type: "notice",
                        infoText: "到底部了",
                        autoClose: 2500,
                        position: "bottom"  // center: 居中; bottom: 底部
                    });
                }
            }
        })


    })


</script>


</body>
</html>